"""
try:
    f = open("../thread-1.py", 'r', encoding='utf-8')
    print(f.read())
finally:
    if f:
        f.close()

"""

"""
with open('../thread-1.py', 'r', encoding='utf-8') as f:
    print(f.read())
    
"""

"""
如果文件很小，read()一次性读取最方便；如果不能确定文件大小，反复调用read(size)比较保险；如果是配置文件，调用readlines()最方便：
"""

# 按行读取文件
with open('./config.ini', 'r', encoding='utf-8') as f:
    for line in f.readlines():
        print(line.strip())  # 把末尾的'\n'删掉

# 追加文件
with open('./config.ini', 'a', encoding='utf-8') as f:
    # f.writelines(["\nhello_world=python learn\n"])
    # f.write("hello_world=python learn\n")
    print("hello_world=python learn\n", file=f)


